include "base.thrift"
include "user.thrift"

struct Course{
    1: optional i32 course_id;
    2: string name; // 课程名称
    3: string begin_at; // 课程开始时间，精确至天，形如"2006-01-02"
    4: i32 duration; // 课程时长，单位为天，-1表示"长期"
    5: optional string invite_code; // 邀请码
    6: optional list<user.Member> members;
    7: optional list<Directory> directories;
    8: string created_at; // 创建时间
    9: i32 members_count; // 成员人数
}

struct CreateCourseResponse{
    1: base.Meta meta;
    2: Course course;
}

struct CreateCourseRequest{
    1: string name;
    2: string begin_at;
    3: i32 duration;
}

struct DeleteCourseResponse{
    1: base.Meta meta;
}

struct DeleteCourseRequest{
    1: i32 course_id;
}

struct Directory{
    1: optional i32 directory_id;
    2: string name;
    3: i32 course_id;
}

struct CreateDirectoriesRequest{
    1: list<Directory> directories;
}

struct CreateDirectoriesResponse{
    1: base.Meta meta;
    2: list<Directory> directories;
}

struct JoinCourseRequest{ // 可选，course_id和invite_code任意一个有值即可
    1: optional i32 course_id;
    2: optional string invite_code;
}

struct JoinCourseResponse{
    1: base.Meta meta;
}

struct GetCourseRequest{
    1: i32 course_id;
}

struct GetCourseResponse{
    1: base.Meta meta;
    2: Course course;
}

struct GetCoursesRequest{
    1: i32 limit;
    2: i32 offset;
}

struct GetCoursesResponse{
    1: base.Meta meta;
    2: list<Course> courses;
}

service CourseService{
    CreateCourseResponse CreateCourse(1: CreateCourseRequest req)(api.post="/course")
    DeleteCourseResponse DeleteCourse(1: DeleteCourseRequest req)(api.delete="/course")
    GetCourseResponse GetCourse(1: GetCourseRequest req)(api.post="/get_course_detail")
    GetCoursesResponse GetCourses(1: GetCoursesRequest req)(api.post="/get_courses") // 获取课程列表
    JoinCourseResponse JoinCourse(1: JoinCourseRequest req)(api.post="/course/join")
    CreateDirectoriesResponse CreateDirectories(1: CreateDirectoriesRequest req)(api.post="/course/directories")
}